home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
surfmodl.arc
/
UNDIGEST.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1987-05-01
|
3KB
|
82 lines
{ UNDIGEST.PAS: Undigestify data from the input stream, and send output to
named files. This program is used to break up the input stream (a "digest"
of files) into many smaller files, stripping off any leading and trailing
garbage, and preserve their original filenames. The beginning of each
new file in the input stream is assumed to be marked by a line that starts
with at least 6 dashes, and has the string "CUT HERE FOR flnm" somewhere
on the line. The name specified (flnm) is used to name the file. Undigest also
recognizes a special line of the same form (starting with at least 6 dashes),
but containing the string "END OF DIGEST" somewhere on the line. This should
be used to mark the end of the last file in the digest, to avoid any
trailing data from being included in the last file. If this line is left
off, a warning will be issued but the error is not fatal. One other note:
Any lines at the beginning of the digest, before the first file marker line,
are ignored. Invoke Undigest with a command of the form:
UNDIGEST < flnm
where flnm is the name of the file containing the full digest.
Programmed by Ken Van Camp <kvancamp@ARDEC.ARPA>, April, 1987.
}
{$G16384,D-} { Enable input redirection in Turbo Pascal }
program UNDIGEST;
var Line: string[127]; { a line of input }
Npos: integer; { position of a string in the line }
Filopen: boolean; { is a file open now? }
Filout: text; { the output file }
Filname: string[40]; { name of output file }
begin
Filopen := FALSE;
while (not eof) do begin
readln (Line);
Npos := pos ('------', Line);
if (Npos = 1) then begin
{ found a line starting with dashes; begin new file or end of last }
{ find the name of the next file }
Npos := pos ('CUT HERE FOR ', Line);
if (Npos > 0) then begin
{ valid line; close the old file if it's open }
if (Filopen) then
close (Filout);
{ get the filename }
Filname := copy (Line, Npos+13, 40);
{ strip off any trailing blanks and dashes }
Npos := pos (' ', Filname);
if (Npos > 0) then
Filname := copy (Filname, 1, Npos-1);
{ next line in case they forgot to skip a space before the dashes }
Npos := pos ('-', Filname);
if (Npos > 0) then
Filname := copy (Filname, 1, Npos-1);
writeln ('Opening file for output: ', Filname);
assign (Filout, Filname);
rewrite (Filout);
Filopen := TRUE;
end else begin
{ check for end-of-digest marker }
Npos := pos ('END OF DIGEST', Line);
if (Npos > 0) then begin
writeln ('End marker found; normal termination');
if (Filopen) then
close (Filout);
halt;
end;
{ Just a normal line; echo it if file's open }
if (Filopen) then
writeln (Filout, Line);
end; { if (Npos > 0) }
end else begin
{ Just a normal line; echo it if file's open }
if (Filopen) then
writeln (Filout, Line);
end; { if (Npos = 1) }
end; { while }
if (Filopen) then begin
close (Filout);
writeln ('Warning: End of last file with no end marker read');
end else
writeln ('Error: No file separators found!');
end. { program UNDIGEST }